package com.cn.service.company;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cn.dao.company.CompanyDao;
import com.cn.entity.TbCompany;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 公司顾客service层实现
 * @Date 2021/6/4 11:37
 * @Package com.cn.service.company
 * @Version 1.0
 */

@Service
public class CompanyServiceImpl implements CompanyService{

    @Autowired
    private CompanyDao companyDao;

    @Override
    public List<TbCompany> companys() {
        return companyDao.selectList(null);
    }

    /*
        分页所有公司信息
         */
    @Override
    public Page<TbCompany> allTbCompany(String name, String companyNo, String owner, Integer pageNum) {
        QueryWrapper<TbCompany> wrapper = new QueryWrapper<>();
        if (name!=null){
            wrapper.like("name",name);
        }
        if (companyNo!=null&&!"".equals(companyNo)){
            wrapper.like("companyNo",companyNo);
        }
        if (owner!=null&&!"".equals(owner)){
            wrapper.like("owner",owner);
        }
        Page<TbCompany> page = new Page<>(pageNum,10);
        return companyDao.selectPage(page,wrapper);
    }
    /*
    添加公司信息
     */
    @Override
    public int addCompany(TbCompany tbCompany) {
        return companyDao.insert(tbCompany);
    }
    /*
    根据id查询公司信息
     */
    @Override
    public TbCompany queryById(Long id) {
        TbCompany tbCompany = companyDao.selectById(id);
        return tbCompany;
    }
    /*
    更新公司信息
     */
    @Override
    public int updateCompany(TbCompany tbCompany) {
        return companyDao.updateById(tbCompany);
    }
    /*
    根据id删除公司信息
     */
    @Override
    public int delById(Long id) {
        return companyDao.deleteById(id);
    }
}
